package com.atguigu.reflect;

import java.lang.reflect.Field;
import java.util.ArrayList;

public class TestMain {
    public static void main(String[] args) throws Exception {
        Class clazz = Class.
                forName("com.atguigu.reflect.Person");
        Person person = (Person) clazz.newInstance();
        // name名称
        Field f = clazz.getDeclaredField("name");
        //表示私有属性可直接操作
        f.setAccessible(true);
        f.set(person, "yxy");
        String name = (String) f.get(person);
        System.out.println(name);

        //获取属性修饰符
        int modifiers = f.getModifiers();
        System.out.println(modifiers);
        // 获取属性的类型
        Class fclss = f.getType();
        //获取属性名字
        String name1 = f.getName();
        System.out.println(name1);


        Class clazz2 = ArrayList.class;
        //获取ArrayList的父类
        Class sclass = clazz2.getSuperclass();
        System.out.println(sclass.getName());
        Package aPackage = clazz2.getPackage();
        System.out.println(aPackage);


        Class[] interfaces = clazz.getInterfaces();
        for (Class anInterface : interfaces) {
            System.out.println(anInterface);
        }



    }
}
